home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # GDeviceUtils.cp
- #
- # by Eric Traut
- #
- ------------------------------------------------------------------------------*/
-
- #include "GDeviceUtils.h"
-
- #include <Memory.h>
- #include <LowMem.h>
- #include <Displays.h>
- #include <Traps.h>
-
-
-
- /*---------------------------------------------------------------
- BlendVirtualDevices
- ---------------------------------------------------------------*/
-
- void
- SimpleBlendEffect::BlendVirtualDevices(
- const GraphicSurface & inDestSurface,
- VirtualGDevice ** inVDeviceList,
- UInt32 inVDeviceCount)
- {
- #pragma unused (inVDeviceCount)
-
- // The simple blend effect simply involves
- // copying the pixels from the first virtual
- // device to the destination surface.
- UInt32 totalRows = inDestSurface.GetHeight();
- UInt32 totalCols = inDestSurface.GetWidth();
- UInt8 * srcPtr;
- UInt8 * destPtr;
-
- for (UInt32 row = 0; row < totalRows; row++)
- {
- srcPtr = inVDeviceList[0]->GetGraphicSurface().GetPixelDataPtr() +
- inVDeviceList[0]->GetGraphicSurface().GetRowBytes() * row;
- destPtr = inDestSurface.GetPixelDataPtr() + inDestSurface.GetRowBytes() * row;
-
- if (((((long)srcPtr) | ((long)destPtr)) & 15) == 0) {
- for (UInt32 col = 0; col < totalCols; col+=sizeof(double)/2) {
- ((double *)destPtr)[0] = ((double *)srcPtr)[0];
- ((double *)destPtr)[1] = ((double *)srcPtr)[1];
- srcPtr += 2 * sizeof(double);
- destPtr += 2 * sizeof(double);
- }
- } else {
- for (UInt32 col = 0; col < totalCols; col+=2) {
- *(UInt32 *)destPtr = *(UInt32 *)srcPtr;
- srcPtr += 4;
- destPtr += 4;
- }
- }
- }
- }
-
-
- /*---------------------------------------------------------------
- DimVariably
- ---------------------------------------------------------------*/
-
- UInt16 *
- ThrobEffect::DimVariably(
- UInt16 *in,
- UInt16 *out,
- int ratio,
- int count,
- int start,
- int stop)
- {
- UInt16 *outer = out;
- UInt16 *inner = in;
-
- int row;
-
- for (row = 0; row < start && row < count; row++) {
- *outer++ = *inner++;
- }
- for ( ; row < stop && row < count; row++) {
- int inPixel1 = *inner++;
-
- UInt32 red = (((inPixel1 >> 10) & 0x1f) * ratio + 31) >> 6;
- UInt32 green = (((inPixel1 >> 5) & 0x1f) * ratio + 31) >> 6;
- UInt32 blue = ((inPixel1 & 0x1f) * ratio + 31) >> 6;
-
- *outer++ = ((red) << 10) | ((green) << 5) | (blue);
- }
- for ( ; row < count; row++) {
- *outer++ = *inner++;
- }
- return out;
- }
-
-
- /*---------------------------------------------------------------
- BlendVirtualDevices
- ---------------------------------------------------------------*/
-
- UInt16 Row[8192];
-
- void
- ThrobEffect::BlendVirtualDevices(
- const GraphicSurface & inDestSurface,
- VirtualGDevice ** inVDeviceList,
- UInt32 inVDeviceCount)
- {
- #pragma unused (inVDeviceCount)
-
- // The simple blend effect simply involves
- // copying the pixels from the first virtual
- // device to the destination surface.
- UInt32 totalRows = inDestSurface.GetHeight();
- UInt32 totalCols = inDestSurface.GetWidth();
- UInt8 * srcPtr;
- UInt8 * destPtr;
-
- int ticks = LMGetTicks();
- int dimRatio = ticks & 63;
- if (ticks & 64) dimRatio = 63 - dimRatio;
-
- UInt16 *rowPtr = &Row[0];
-
- rowPtr = (UInt16 *) (-32 & (31 + (int)rowPtr));
-
- Rect OKRect = *(Rect *)0x40;
-
- for (UInt32 row = 0; row < totalRows; row++)
- {
- srcPtr = inVDeviceList[0]->GetGraphicSurface().GetPixelDataPtr() +
- inVDeviceList[0]->GetGraphicSurface().GetRowBytes() * row;
- destPtr = inDestSurface.GetPixelDataPtr() + inDestSurface.GetRowBytes() * row;
-
- if (row >= OKRect.top && row < OKRect.bottom) {
- srcPtr = (UInt8 *)DimVariably((UInt16 *)srcPtr, Row, dimRatio & (-4), totalCols, OKRect.left, OKRect.right);
- }
-
- if (((((long)srcPtr) | ((long)destPtr)) & 15) == 0) {
- for (UInt32 col = 0; col < totalCols; col+=sizeof(double)/2) {
- ((double *)destPtr)[0] = ((double *)srcPtr)[0];
- ((double *)destPtr)[1] = ((double *)srcPtr)[1];
- srcPtr += 2 * sizeof(double);
- destPtr += 2 * sizeof(double);
- }
- } else {
- for (UInt32 col = 0; col < totalCols; col+=2) {
- *(UInt32 *)destPtr = *(UInt32 *)srcPtr;
- srcPtr += 4;
- destPtr += 4;
- }
- }
- }
- }
-
-
- /*---------------------------------------------------------------
- SetEffectValue
- ---------------------------------------------------------------*/
-
- void
- DontThrobEffect::SetEffectValue(
- UInt16 inValueIndex,
- double inValue)
- {
- if (inValueIndex == 0)
- mPrimaryScreenFraction = inValue;
- }
-
-
- /*---------------------------------------------------------------
- DimVariably
- ---------------------------------------------------------------*/
-
- UInt16 *
- DontThrobEffect::DimVariably(
- UInt16 *in,
- UInt16 *out,
- int ratio,
- int count,
- int start,
- int stop)
- {
- UInt16 *outer = out;
- UInt16 *inner = in;
-
- int row;
-
- for (row = 0; row < start && row < count; row++) {
- int inPixel1 = *inner++;
-
- UInt32 red = (((inPixel1 >> 10) & 0x1f) * ratio + 31) >> 6;
- UInt32 green = (((inPixel1 >> 5) & 0x1f) * ratio + 31) >> 6;
- UInt32 blue = ((inPixel1 & 0x1f) * ratio + 31) >> 6;
-
- *outer++ = ((red) << 10) | ((green) << 5) | (blue);
- }
- if (stop != start) { *(short *)0x54 = row; *(short *)0x56 = start; *(short *)0x58 = stop; *(short *)0x5A = count; }
- for ( ; row < stop && row < count; row++) {
- *(long *)0x50 += 1;
- *outer++ = *inner++;
- }
- for ( ; row < count; row++) {
- int inPixel1 = *inner++;
-
- UInt32 red = (((inPixel1 >> 10) & 0x1f) * ratio + 31) >> 6;
- UInt32 green = (((inPixel1 >> 5) & 0x1f) * ratio + 31) >> 6;
- UInt32 blue = ((inPixel1 & 0x1f) * ratio + 31) >> 6;
-
- *outer++ = ((red) << 10) | ((green) << 5) | (blue);
- }
- return out;
- }
-
-
- /*---------------------------------------------------------------
- BlendVirtualDevices
- ---------------------------------------------------------------*/
-
- void
- DontThrobEffect::BlendVirtualDevices(
- const GraphicSurface & inDestSurface,
- VirtualGDevice ** inVDeviceList,
- UInt32 inVDeviceCount)
- {
- #pragma unused (inVDeviceCount)
-
- // The simple blend effect simply involves
- // copying the pixels from the first virtual
- // device to the destination surface.
- UInt32 totalRows = inDestSurface.GetHeight();
- UInt32 totalCols = inDestSurface.GetWidth();
- UInt8 * srcPtr;
- UInt8 * destPtr;
-
- int ticks = LMGetTicks();
- int dimRatio = ticks & 63;
- if (ticks & 64) dimRatio = 63 - dimRatio;
-
- UInt16 *rowPtr = &Row[0];
-
- rowPtr = (UInt16 *) (-32 & (31 + (int)rowPtr));
-
- Rect OKRect = *(Rect *)0x40;
- InsetRect(&OKRect, 1, 1);
-
- for (UInt32 row = 0; row < totalRows; row++)
- {
- srcPtr = inVDeviceList[0]->GetGraphicSurface().GetPixelDataPtr() +
- inVDeviceList[0]->GetGraphicSurface().GetRowBytes() * row;
- destPtr = inDestSurface.GetPixelDataPtr() + inDestSurface.GetRowBytes() * row;
-
- if (OKRect.top < OKRect.bottom && OKRect.left < OKRect.right) {
- if (row >= OKRect.top && row < OKRect.bottom) {
- srcPtr = (UInt8 *)DimVariably((UInt16 *)srcPtr, Row, dimRatio & (-4), totalCols, OKRect.left, OKRect.right);
- } else {
- srcPtr = (UInt8 *)DimVariably((UInt16 *)srcPtr, Row, dimRatio & (-4), totalCols, 0x7FFF, 0x7FFF);
- }
- }
-
- if (((((long)srcPtr) | ((long)destPtr)) & 15) == 0) {
- for (UInt32 col = 0; col < totalCols; col+=sizeof(double)/2) {
- ((double *)destPtr)[0] = ((double *)srcPtr)[0];
- ((double *)destPtr)[1] = ((double *)srcPtr)[1];
- srcPtr += 2 * sizeof(double);
- destPtr += 2 * sizeof(double);
- }
- } else {
- for (UInt32 col = 0; col < totalCols; col+=2) {
- *(UInt32 *)destPtr = *(UInt32 *)srcPtr;
- srcPtr += 4;
- destPtr += 4;
- }
- }
- }
- }
-
-
-
-
-
-